!include "MUI2.nsh" 

!define PRODUCTNAME "Portal Planner"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SetCompressor /solid lzma

!define ADDREMOVECP_NAME "Portal Planner"
!define DEF_INSTALL_DIR "Portal Planner"
!define STARTMENUFOLDER "Portal Planner"
!define REGUNINSTKEY PortalPlanner


!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\Requirements.txt"
!define MUI_FINISHPAGE_SHOWREADME_CHECKED
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Show 3rd party packages to be installed"


Name "${PRODUCTNAME}"

BrandingText /TRIMLEFT " "
;!define MUI_UNICON "uninstall.ico"

!include "MUI.nsh"

;Var MUI_TEMP
Var STARTMENU_FOLDER

;Remember the Start Menu Folder
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\${STARTMENUFOLDER}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"

;General
OutFile "Install Portal Planner 1.x.exe"

;Folder selection page
InstallDir "$PROGRAMFILES\${DEF_INSTALL_DIR}"

  CRCCheck On

;  !define MUI_HEADERIMAGE
;  !define MUI_HEADERIMAGE_BITMAP "header.bmp"

  !define MUI_FINISHPAGE_RUN "$INSTDIR\PortalPlan.exe"
  !define MUI_FINISHPAGE_RUN_NOTCHECKED

;  !define MUI_FINISHPAGE_NOAUTOCLOSE

  !insertmacro MUI_PAGE_WELCOME
;  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
  !insertmacro MUI_PAGE_INSTFILES
  !insertmacro MUI_PAGE_FINISH
  
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES 

  !insertmacro MUI_LANGUAGE "English"
  LangString DESC_SecApp ${LANG_ENGLISH} "Install Portal Planner"


  InstType "Full Installation"

Section "Application" SecApp
  SectionIn 1

	!include WordFunc.nsh
	!include LogicLib.nsh

  SetOutPath "$INSTDIR"
  File "..\PortalPlan\bin\Release\PortalPlan.exe"
  File "..\PortalPlan\bin\Release\Google.OrTools.LinearSolver.dll"
  File "..\PortalPlan\bin\Release\PortalPlan-IP.exe"
  File "..\PortalPlan\bin\Release\PP-Classes.dll"
  File "..\Requirements.txt"

  SetOutPath "$INSTDIR\Samples"
  File "..\Samples\Cockatoo Island.pplan"
  File "..\Samples\Hyde Park.pplan"
  File "..\Samples\Parramatta.pplan"

  CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
  CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Portal Planner.lnk" "$INSTDIR\PortalPlan.exe"
  CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe"

  WriteUninstaller "$INSTDIR\Uninstall.exe"

  ; Create uninstall registry entries for add/remove on control panel
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUNINSTKEY}" "DisplayName" "${ADDREMOVECP_NAME}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUNINSTKEY}" "UninstallString" "$INSTDIR\Uninstall.exe"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUNINSTKEY}" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUNINSTKEY}" "NoRepair" 1
SectionEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;--------------------------------------------------------------------------------
;                    UNINSTALLER SECTION

Section "Uninstall"
  !insertmacro MUI_STARTMENU_GETFOLDER Application $STARTMENU_FOLDER

  Delete "$INSTDIR\PortalPlan.exe"
  Delete "$INSTDIR\PortalPlan-IP.exe"
  Delete "$INSTDIR\Google.OrTools.LinearSolver.dll"
  Delete "$INSTDIR\PP-Classes.dll"
  Delete "$INSTDIR\Requirements.txt"
  Delete "$INSTDIR\Uninstall.exe"
  Delete "$INSTDIR\Samples\Cockatoo Island.pplan"
  Delete "$INSTDIR\Samples\Hyde Park.pplan"
  Delete "$INSTDIR\Samples\Parramatta.pplan"
  RmDir "$INSTDIR\Samples"
  RmDir "$INSTDIR"
  Delete "$SMPROGRAMS\$STARTMENU_FOLDER\Portal Planner.lnk"
  Delete "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk"
  RmDir "$SMPROGRAMS\$STARTMENU_FOLDER"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUNINSTKEY}"
SectionEnd


!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${SecApp} $(DESC_SecApp)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
